package com.zzg.test2.adapter

import android.content.Context
import android.view.LayoutInflater
import android.view.ViewGroup
import androidx.core.content.ContextCompat
import androidx.recyclerview.widget.RecyclerView
import com.zzg.test2.R
import com.zzg.test2.databinding.ItemMainTabBinding
import com.zzg.test2.listener.ItemClickListener


/**
 *
 * @ClassName: HomeTabAdapter
 * @Description:
 * @Author: zhouzhiguo
 * @Date: 2025/8/27 17:10
 * @Version: 5.3.8
 */

class HomeTabAdapter(val mContext: Context) : RecyclerView.Adapter<HomeTabAdapter.ViewHolder>() {

    var itemClickListener: ItemClickListener? = null
    var noSelectArr = intArrayOf(R.drawable.ic_tab_1, R.drawable.ic_tab_2, R.drawable.ic_tab_3, R.drawable.ic_tab_4, R.drawable.ic_tab_5)


    var selectArr = intArrayOf(R.drawable.ic_tab_press_1, R.drawable.ic_tab_press_2, R.drawable.ic_tab_press_3, R.drawable.ic_tab_press_4, R.drawable.ic_tab_press_5)
    /**
     * 当前选中
     */
    var selectPos = 0;

    override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ViewHolder {
        val binding = ItemMainTabBinding.inflate(LayoutInflater.from(parent.context), parent, false)
        return ViewHolder(binding)
    }
    override fun getItemCount(): Int {
        return selectArr.size
    }

    override fun onBindViewHolder(holder: ViewHolder, position: Int) {
        holder.binding.apply {
            if (position == selectPos){
               icon.background = ContextCompat.getDrawable(mContext,selectArr[position])
            }else{
               icon.background = ContextCompat.getDrawable(mContext,noSelectArr[position])
            }

            item.setOnClickListener {
                //策略支付详情
                if (itemClickListener != null) {
                    selectPos = position
                    itemClickListener!!.onRecyclerItemClick(holder.adapterPosition, it)
                    notifyDataSetChanged()
                }

            }
        }

    }

     class ViewHolder(val binding: ItemMainTabBinding) : RecyclerView.ViewHolder(binding.root)

}